package health_system.health_system.service;

import health_system.health_system.entity.RefreshToken;
import health_system.health_system.entity.User;

import java.util.List;
import java.util.Optional;

public interface RefreshTokenService {
    
    /**
     * Create a new refresh token for a user
     * 
     * @param userId the user ID
     * @param deviceId the device ID (optional, for mobile clients)
     * @param deviceType the device type (optional, for mobile clients)
     * @param ipAddress the IP address of the client
     * @return the created refresh token
     */
    RefreshToken createRefreshToken(Long userId, String deviceId, String deviceType, String ipAddress);
    
    /**
     * Verify if a refresh token is valid
     * 
     * @param token the refresh token
     * @return the verified refresh token
     */
    RefreshToken verifyExpiration(RefreshToken token);
    
    /**
     * Find a refresh token by its token value
     * 
     * @param token the token value
     * @return the refresh token or empty if not found
     */
    Optional<RefreshToken> findByToken(String token);
    
    /**
     * Delete a refresh token
     * 
     * @param token the refresh token to delete
     */
    void deleteToken(RefreshToken token);
    
    /**
     * Delete all refresh tokens for a user
     * 
     * @param user the user
     */
    void deleteByUser(User user);
    
    /**
     * Get all refresh tokens for a user
     * 
     * @param user the user
     * @return list of all refresh tokens for the user
     */
    List<RefreshToken> findAllByUser(User user);
    
    /**
     * Revoke all tokens for a user
     * 
     * @param user the user
     */
    void revokeAllUserTokens(User user);
    
    /**
     * Revoke all tokens for a user on a specific device
     * 
     * @param user the user
     * @param deviceId the device ID
     */
    void revokeUserTokensForDevice(User user, String deviceId);
    
    /**
     * Clean up expired tokens
     */
    void cleanExpiredTokens();
} 